package com.baize.cpdepus.common;


import com.baize.cpdepus.entity.LoginUser;
import com.baize.cpdepus.entity.User;
import com.baize.cpdepus.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class TokenApplication implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User one = userMapper.SelectOne(Long.valueOf(username));
        if (Objects.isNull(one)) {
            throw new UsernameNotFoundException("用户名或密码错误！");
        }
        return new LoginUser(one);

    }
}
